package com.xmy.cultivate.mapper;

import com.xmy.cultivate.entity.RolePermission;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.xmy.cultivate.entity.StaffPermission;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author min
 * @since 2022-09-25
 */
public interface RolePermissionMapper extends BaseMapper<RolePermission> {


    @Select("select permission_id from role_permission where role_id = #{roleId}")
    public abstract List<Long> getIdListForRoleId(@Param("roleId") Long roleId);

    @Select({"<script>",
            "SELECT DISTINCT permission_id ",
            "FROM ",
            "role_permission ",
            "WHERE ",
            "role_id IN ( ",
            "SELECT ",
            "role_id ",
            "FROM ",
            "role_admin ",
            "WHERE ",
            "admin_id = ( SELECT admin_id FROM staff WHERE id = ${staffId} )) ",
            "AND permission_id NOT IN ( SELECT permission_id FROM staff_permission WHERE staff_id = ${staffId} AND type = 2 ) ",
            "</script>"})
    public List<Long> getRolePermissionAllByStaffId(@Param("staffId") String staffId);

    /**
     * 获取财务角色权限
     */
    @Select("SELECT DISTINCT permission_id FROM role_permission WHERE role_id IN (${roleId}) ")
    public List<Long> getRolePermissionByRoleId(@Param("roleId") String roleId);

    /**
     * 获取教务角色权限
     */
    @Select("SELECT DISTINCT permission_id FROM mobile_role_permission WHERE role_id IN (${roleId}) ")
    public List<Long> getMobileRolePermissionByRoleId(@Param("roleId") String roleId);
}
